package com.data.modules.online.cgreport.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.data.common.api.vo.Result;
import com.data.common.system.base.controller.BootController;
import com.data.common.system.query.QueryGenerator;
import com.data.modules.online.cgform.util.CgformUtil;
import com.data.modules.online.cgreport.entity.OnlCgreportParam;
import com.data.modules.online.cgreport.service.IOnlCgreportParamService;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/online/cgreport/param")
@RestController("onlCgreportParamController")
public class OnlCgreportParamController {

    private static final Logger f346a = LoggerFactory.getLogger(OnlCgreportParamController.class);
    @Autowired
    private IOnlCgreportParamService onlCgreportParamService;

    /** 动态报表配置明细 列表
     * @param headId
     * @return
     */
    @ApiOperation("动态报表配置明细 列表")
    @GetMapping({"/listByHeadId"})
    public Result<?> listByHeadId(@RequestParam("headId") String headId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("cgrhead_id", headId);
        queryWrapper.orderByAsc("order_num");
        List list = this.onlCgreportParamService.list(queryWrapper);
        return Result.ok(list);
    }

    @GetMapping({"/list"})
    public Result<IPage<OnlCgreportParam>> mo1042a(OnlCgreportParam onlCgreportParam, @RequestParam(defaultValue = "1", name = "pageNo") Integer num, @RequestParam(defaultValue = "10", name = "pageSize") Integer num2, HttpServletRequest httpServletRequest) {
        Result<IPage<OnlCgreportParam>> result = new Result<>();
        Wrapper initQueryWrapper = QueryGenerator.initQueryWrapper(onlCgreportParam, httpServletRequest.getParameterMap());
        IPage page = this.onlCgreportParamService.page(new Page((long) num.intValue(), (long) num2.intValue()), initQueryWrapper);
        result.setSuccess(true);
        result.setResult(page);
        return result;
    }

    @PostMapping({"/add"})
    public Result<?> mo1041a(@RequestBody OnlCgreportParam onlCgreportParam) {
        this.onlCgreportParamService.save(onlCgreportParam);
        return Result.ok("添加成功!");
    }

    @PutMapping({"/edit"})
    public Result<?> mo1044b(@RequestBody OnlCgreportParam onlCgreportParam) {
        this.onlCgreportParamService.updateById(onlCgreportParam);
        return Result.ok("编辑成功!");
    }

    @DeleteMapping({"/delete"})
    public Result<?> mo1043b(@RequestParam(name = "id", required = true) String str) {
        this.onlCgreportParamService.removeById(str);
        return Result.ok("删除成功!");
    }

    @DeleteMapping({"/deleteBatch"})
    public Result<?> mo1045c(@RequestParam(name = "ids", required = true) String str) {
        this.onlCgreportParamService.removeByIds(Arrays.asList(str.split(CgformUtil.f231E)));
        return Result.ok("批量删除成功!");
    }

    @GetMapping({"/queryById"})
    public Result<OnlCgreportParam> mo1046d(@RequestParam(name = "id", required = true) String str) {
        Result<OnlCgreportParam> result = new Result<>();
        result.setResult((OnlCgreportParam) this.onlCgreportParamService.getById(str));
        return result;
    }
}
